<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <link rel="stylesheet" href="/node_modules/bootstrap/dist/css/bootstrap.min.css">
  <title>Home Page</title>
</head>
<body>
  <div class="container">
    <div class="header" style="padding: 50px 0;">
      <h2>Hello Register Login Project</h2>
      <h6>This project is based on Node.Js, Express, MongoDB.</h6>
      {{ if sessionRoot }}
        Username:<strong class="text-right" style="color: #0f0;">{{ sessionRoot.username }}</strong>
      {{ /if }}
    </div>
    <div class="buttonGroup">
      <a href="/login"><button type="button" class="btn btn-outline-primary">Login</button></a>
      <a href="/register"><button type="button" class="btn btn-outline-primary">Register</button></a>
    </div>
    <hr>
    <div class="main">
      <table class="table table-striped table-hover table-sm">
        <thead>
          <tr>
            <th scope="col">#</th>
            <th scope="col">姓名</th>
            <th scope="col">性别</th>
            <th scope="col">电话号码</th>
            <th scope="col">简介</th>
            <th scope="col">操作</th>
          </tr>
        </thead>
        <tbody>
          {{ each roots}}
          <tr>
            <th scope="row">{{ $index + 1 }}</th>
            <td>{{ $value.username }}</td>
            <td>{{ ($value.gender=='0')?'man':'woman' }}</td>
            <td>{{ $value.telephone }}</td>
            <td>{{ $value.resume }}</td>
            <td>
              <a href="#" onclick="deleteFn('{{ $value.id }}')">删除</a>
            </td>
          </tr>
          {{ /each }}
        </tbody>
      </table>
    </div>
  </div>

  <script src="/node_modules/bootstrap/dist/js/bootstrap.min.js"></script>
  <script src="/node_modules/jquery/dist/jquery.min.js"></script>
  <script>
    $(function () {

    })
    function deleteFn(rid) {
      if (window.confirm("确定删除？")) {
        $.ajax({
          url: '/delete',
          type: 'get',
          data: {
            rid: rid
          },
          dataType: 'json',
          success: function (data) {
            if (data.success) {
              window.alert('删除成功！')
              window.location.href = '/'
            } else {
              window.alert('删除失败！')
            }
          }
        })
      }
    }
  </script>
</body>
</html>